<?php
/**
 * 模块管理
 */
class ModuleController extends AdminBase{
	public function actionIndex(){
		$this->baseIndex('ModuleModel');
	}
	public function actionCreate(){
		if(IS_POST && !empty($_POST['ModuleModel']['TagIDs'])){
			$_POST['ModuleModel']['TagIDs'] = implode(',', $_POST['ModuleModel']['TagIDs']);
		}
		if(IS_POST && !empty($_POST['ModuleModel']['TagListIDs'])){
			$_POST['ModuleModel']['TagListIDs'] = implode(',', $_POST['ModuleModel']['TagListIDs']);
		}
		$this->baseCreate('ModuleModel');
	}
	public function actionUpdate($id){
		$objModel = $this->loadModel($id);
		if(IS_POST && !empty($_POST['ModuleModel']['TagIDs'])){
			$_POST['ModuleModel']['TagIDs'] = implode(',', $_POST['ModuleModel']['TagIDs']);
		}else{
			$objModel->TagIDs = explode(',', $objModel->TagIDs);
		}
		if(IS_POST && !empty($_POST['ModuleModel']['TagListIDs'])){
			$_POST['ModuleModel']['TagListIDs'] = implode(',', $_POST['ModuleModel']['TagListIDs']);
		}else{
			$objModel->TagListIDs = explode(',', $objModel->TagListIDs);
		}
		$this->baseUpdate($objModel);
	}
	public function actionDelete(){
		$this->baseDelete('ModuleModel');
	}

	public function loadModel($id)
	{
		$model=ModuleModel::model()->findByPk($id);
		if($model===null)
			$this->error('找不到记录');
		return $model;
	}

}